package com.dtsheep.rxjava.java8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * FlatmapDemo
 *
 * <p>
 * </p>
 *
 * @author chuanbai
 * @date 2024/5/18
 */
public class FlatmapDemo {
    
    /**
     * flatmap 操作
     *
     * @param
     * @return 
     * @author chuanbai
     * @date ${DATE}
     */
    public void flatmap01(){
        List<String> list = new ArrayList<>();
        list.add("香 蕉");
        list.add("苹 果");

        // flatMap 返回stream流
        List<String> collect = list.stream().flatMap(obj -> {
            return Arrays.stream(obj.split(" "));
        }).collect(Collectors.toList());
        System.out.println(collect);

        // map 返回无限制
        Stream<Object> objectStream1 = list.stream().map(obj -> {
            return obj.split(" ");
        });

    }

    public static void main(String[] args) {
        FlatmapDemo flatmapDemo = new FlatmapDemo();
        flatmapDemo.flatmap01();
    }
}
